<?php

require_once dirname(__FILE__).'/../lib/conceptGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/conceptGeneratorHelper.class.php';

/**
 * concept actions.
 *
 * @package    ideas
 * @subpackage concept
 * @author     AlvaroLara
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class conceptActions extends autoConceptActions
{
  public function executeNew(sfWebRequest $request)
  {
    if ($this->getUser()->isAuthenticated())
    {
      return parent::executeNew($request);
    }
    $this->getUser()->setFlash('error','Only registered users can access this functionality');
    $this->forward('idea','index');
  }

  public function executeEdit(sfWebRequest $request)
  {
    if ($this->getUser()->isAuthenticated())
    {
      return parent::executeEdit($request);
    }
    $this->getUser()->setFlash('error','Only registered users can access this functionality');
    $this->forward('idea','index');
  }


  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $notice = $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.';

      $Concept = $form->save();

      $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $Concept)));

      if ($request->hasParameter('_save_and_add'))
      {
        $this->getUser()->setFlash('notice', $notice.' You can add another one below.');

        $this->redirect('@concept_new');
      }
      else
      {
        $this->getUser()->setFlash('notice', $notice);

        $this->redirect('@idea');
      }
    }
    else
    {
      $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false);
    }
  }

}
